package com.ruoyi.web.controller.webservice.client;

import com.ruoyi.web.controller.webservice.server.WebServiceI;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.springframework.util.Assert;

/*
* webservice客户端中心
* */
public class WSClientCenter {
    private static JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();

    private static final String DEFALUT_ADDR = "";
        /*通过远程地址和接口获取接口实例*/
        public static <T> T getRemoteInterface(String addr,Class<T> clz) {
            //String address = "http://localhost:8080/services/ws/api?wsdl";
            Assert.isTrue(!addr.startsWith("http://"),"请输入正确地址格式");
            jaxWsProxyFactoryBean.setAddress(addr);
            jaxWsProxyFactoryBean.setServiceClass(clz);
            Object obj = jaxWsProxyFactoryBean.create();
            return clz.cast(obj);
        }


        public static <T> T getDefaultRemoteI(Class<T> clz) {
            return getRemoteInterface(DEFALUT_ADDR, clz);
        }




    public static void main(String[] args) {
        WebServiceI remoteInterface = WSClientCenter.getDefaultRemoteI( WebServiceI.class);
    }
}
